package mwt.xml.xdbforms.dbms.metadata.impl;

/**
 * A representation of a table's column containing it's metadata informations
 */
public class ColumnMetadata implements Comparable<ColumnMetadata> {

    /** column name */
    private String name;

    /** SQL type from java.sql.Types */
    private int type;

    /** Data source dependent type name, for a UDT the type name is fully qualified */
    private String typeName;

    /** column size */
    private String size;

    /** is NULL allowed */
    private int nullable;

    /** comment describing column (may be null)  */
    private String remarks;

    /** 
     * default value for the column, which should be interpreted as a string 
     * when the value is enclosed in single quotes (may be null) 
     */
    private String defVal;

    /** ISO rules are used to determine the nullability for a column.
     * YES --- if the parameter can include NULLs
     * NO --- if the parameter cannot include NULLs
     * empty string --- if the nullability for the parameter is unknown
     */
    private String isNullable;

    /** catalog of table that is the scope of a reference attribute
     * (null if DATA_TYPE isn't REF) 
     */
    private String scopeCatalog;

    /** schema of table that is the scope of a reference attribute 
     * (null if the DATA_TYPE isn't REF)  
     */
    private String scopeSchema;

    /** table name that this the scope of a reference attribure
     * (null if the DATA_TYPE isn't REF)
     */
    private String scopeTable;

    /** source type of a distinct type or user-generated Ref type, SQL type
     * from java.sql.Types (null if DATA_TYPE
     * isn't DISTINCT or user-generated REF)
     */
    private short sourceDataType;

    /** Indicates whether this column is auto incremented
     *  YES --- if the column is auto incremented
     * NO --- if the column is not auto incremented
     * empty string --- if it cannot be determined whether the column is auto incremented parameter is unknown
     */
    private String isAutoincrement;

    /** index of column in table (starting at 1) */
    private int ordinalPosition;

    /** Default constructor */
    public ColumnMetadata() {
        super();
    }

    /** Parametric constructor */
    public ColumnMetadata(String name, int type, String typeName, String size,
                            int nullable, String remarks, String defVal,
                            String isNullable, String scopeCatalog, String scopeSchema,
                            String scopeTable, short sourceDataType,
                            String isAutoincrement, int ordinalPosition) {
        this.name = name;
        this.type = type;
        this.typeName = typeName;
        this.size = size;
        this.nullable = nullable;
        this.remarks = remarks;
        this.defVal = defVal;
        this.isNullable = isNullable;
        this.scopeCatalog = scopeCatalog;
        this.scopeSchema = scopeSchema;
        this.scopeTable = scopeTable;
        this.sourceDataType = sourceDataType;
        this.isAutoincrement = isAutoincrement;
        this.ordinalPosition = ordinalPosition;
    }

    @Override
    public int compareTo(ColumnMetadata o) {
        int result = 0;

        if (this.ordinalPosition < o.ordinalPosition) {
                result = -1;
        } else if (this.ordinalPosition > o.ordinalPosition) {
                result = 1;
        }

        return result;
    }

    public String getIsAutoincrement() {
        return isAutoincrement;
    }

    public void setIsAutoincrement(String isAutoincrement) {
        this.isAutoincrement = isAutoincrement;
    }

    public String getIsNullable() {
        return isNullable;
    }

    public void setIsNullable(String isNullable) {
        this.isNullable = isNullable;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getNullable() {
        return nullable;
    }

    public void setNullable(int nullable) {
        this.nullable = nullable;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public String getDefVal() {
        return defVal;
    }

    public void setDefVal(String defVal) {
        this.defVal = defVal;
    }

    public String getScopeCatalog() {
        return scopeCatalog;
    }

    public void setScopeCatalog(String scopeCatalog) {
        this.scopeCatalog = scopeCatalog;
    }

    public String getScopeSchema() {
        return scopeSchema;
    }

    public void setScopeSchema(String scopeSchema) {
        this.scopeSchema = scopeSchema;
    }

    public String getScopeTable() {
        return scopeTable;
    }

    public void setScopeTable(String scopeTable) {
        this.scopeTable = scopeTable;
    }

    public String getSize() {
        return size;
    }

    public void setSize(String size) {
        this.size = size;
    }

    public short getSourceDataType() {
        return sourceDataType;
    }

    public void setSourceDataType(short sourceDataType) {
        this.sourceDataType = sourceDataType;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public int getOrdinalPosition() {
        return ordinalPosition;
    }

    public void setOrdinalPosition(int ordinalPosition) {
        this.ordinalPosition = ordinalPosition;
    }
}
